/**
 * 2018年12月5日下午2:02:19
 * @author 谢进财
 */
package com.baihang.project.ds.dao;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.stereotype.Repository;

import com.baihang.framework.dao.BaseDao;
import com.baihang.project.ds.model.FangYuanModel;
import com.baihang.project.ds.model.dbMap.FangYuanRowMapper;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * @author whati
 *
 */
@Repository
public class RoomMonitorDao extends BaseDao {
	@Autowired
	private FangYuanRowMapper rowMapper;
	
	public List<FangYuanModel> queryForFangYuanList(String sql){
		List<FangYuanModel>  modelList = null;
		try {
			modelList = super.getJdbcTemplate().query(sql, rowMapper);
		}catch (Exception e) {
			// TODO: handle exception
		}
		return modelList;
	}
	
	public boolean batchUpdateRoomGuideList(JSONArray jsonArray) {
		String sql = "update room set D_Monitor=1,D_Operation=? where D_ID=?";
		super.getJdbcTemplate().batchUpdate(sql, new BatchPreparedStatementSetter() {
			public int getBatchSize() {
				return jsonArray.size();
				// 这个方法设定更新记录数，通常List里面存放的都是我们要更新的，所以返回list.size();
			}

			public void setValues(PreparedStatement ps, int i) throws SQLException {
				JSONObject jsonObject = jsonArray.getJSONObject(i);
					
				ps.setString(1, jsonObject.getString("tel"));
				ps.setInt(2, Integer.valueOf(jsonObject.getString("roomid")));
				
			}
		});

		return true;
	}
}
